package com.leetcode;

public class No24 {
    public ListNode swapPairs(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode temp = head;
        ListNode pre = null;
        while (temp != null && temp.next != null) {
            ListNode next = temp.next;
            temp.next = next.next;
            next.next = temp;
            if (pre == null) {
                head = next;
            } else {
                pre.next = next;
            }
            pre = temp;
            temp = temp.next;
        }
        return head;
    }
}
